const fsPromise = require("fs/promises");
/**
 * 判断路径是否为文件夹
 * @param {*} dir
 * @returns
 */
exports.isDirectory = function (dir) {
  return new Promise(async (resolve, reject) => {
    const isAccess = await fsPromise
      .access(dir)
      .then(() => true)
      .catch(reject);
    if (!isAccess) {
      return;
    }
    const stat = await fsPromise.stat(dir).catch(reject);

    if (stat) {
      const isdir = stat.isDirectory();
      resolve(isdir);
      return;
    }
  });
};
